var bot = new ChatSDK({
    config: {
        navbar: {
            title: '大聪明'
        },
        robot: {
            avatar: '/images/pic02.ico'
        },
        user: {
            avatar: '/images/pic03.ico'
        },
        messages: [
            {
                type: 'text',
                content: {
                    text: '请输入你的问题'
                }
            }
        ]
    },
    requests: {
        send: function (msg) {
            if (msg.type === 'text') {
                // let data = {"q": "test"}
                return {
                    url: '/open-ai/ask',
                    data: {q: msg.content.text},
                };
            }
        }
    },
    handlers: {
        parseResponse: function (res, requestType) {
            if (requestType === 'send' && res.code === 1) { // 请求成功
                console.log(res.data)
                return res.data.answer;
            }

            return res;
        }
    }
});

bot.run();
// let data = {"q": "test"}
// let request = new XMLHttpRequest();
// request.open('POST', '/open-ai/ask', true)
// request.setRequestHeader("Content-type", "application/json")
// request.send(JSON.stringify(data))
